import 'package:basic_common/common_exports.dart';
import 'package:basic_common/common_utils.dart';

class RegisterController extends GetxController {
  TextEditingController phoneController = TextEditingController();
  final isRead = false.obs;
  final btnIsEnable = false.obs;
  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }

  /// 获取验证码 方法
  void postSmsCode() async {
    String phone = phoneController.value.text;
    if (!CommonUtils.isChinaPhoneLegal(phone)) {
      ToastUtils.toast("手机号格式错误，请重新输入");
      return;
    }
    if (phone.isEmpty) {
      ToastUtils.toast("手机号不能为空");
      return;
    }
    if (!isRead.value) {
      ToastUtils.toast("请先阅读隐私协议");
      return;
    }
    HttpData? res =
        await ApiService().smsReq(data: {"phone": phone}, isShowLoading: true);
    if (res!.code == 1) {
      printInfo(info: "获取成功");
      Get.toNamed(AppRoutes.smsCode, arguments: {"number": phone, "type": 2});
    }
    phoneController.text = "";
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    phoneController.dispose();
  }
}
